package com.yc.class_attendance.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yc.class_attendance.R;
import com.yc.class_attendance.entity.AttendanceResutl;
import com.yc.class_attendance.entity.PersonnelResutl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by PC on 2017/4/11.
 */

public class RecordAdapter extends BaseAdapter {
    Context context;
    List<AttendanceResutl.CourseBean.ListBean> mlist ;


    public RecordAdapter(Context context) {
        this.context = context;

    }
    public RecordAdapter(Context context , List<AttendanceResutl.CourseBean.ListBean>  list) {
        this.context = context;
        this.mlist =list;

    }
    public void setDateSort(List<AttendanceResutl.CourseBean.ListBean> ml){
        if(mlist!=null && mlist.size()>0){
            mlist.clear();
        }
        mlist.addAll(ml);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mlist .size();
    }

    @Override
    public Object getItem(int i) {
        return mlist .get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;

        if (viewHolder == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_attendance, null);
            viewHolder.textView = (TextView) view.findViewById(R.id.te);
            viewHolder.textView1 = (TextView) view.findViewById(R.id.text1);

            viewHolder.iv_type = (ImageView) view.findViewById(R.id.iv_type);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        if (mlist .get(i).getXm().length()==2){
            viewHolder.textView.setText(mlist .get(i).getXm()+"        ");
        }else if(mlist .get(i).getXm().length()==3) {
            viewHolder.textView.setText(mlist .get(i).getXm()+"     ");
        }else {
            viewHolder.textView.setText(mlist .get(i).getXm());
        }
        if(TextUtils.isEmpty(mlist .get(i).getTime())){
            viewHolder.textView1.setText("00:00:00");
        }else{
            viewHolder.textView1.setText(mlist .get(i).getTime());
        }


        Log.d("TAG","list:"+mlist .get(i).getType());
        if (mlist .get(i).getType() == 0) {
            if(!TextUtils.isEmpty(mlist.get(i).getIsLeave()) && "1".equals(mlist.get(i).getIsLeave())){
                viewHolder.iv_type.setImageResource(R.mipmap.index_leave);
            }else{
                viewHolder.iv_type.setImageResource(R.mipmap.index__weixuanzhongyishuaka_icon_one);
            }

        } else if(mlist .get(i).getType() == 1) {
            viewHolder.iv_type.setImageResource(R.mipmap.index__xuanzhongyishuaka_icon_one);
            viewHolder.textView.setTextColor(Color.parseColor("#9d2824"));
            viewHolder.textView1.setTextColor(Color.parseColor("#9d2824"));

        }else if(mlist .get(i).getType() == 2) {
            viewHolder.iv_type.setImageResource(R.mipmap.index__xuanzhongyishuaka_icon_no_tui);
            viewHolder.textView.setTextColor(Color.parseColor("#c4110c"));
            viewHolder.textView1.setTextColor(Color.parseColor("#c4110c"));

        }

        return view;
    }

    public final class ViewHolder {
        TextView textView;
        TextView textView1;
        ImageView iv_type;
    }
}
